package com.example.home_stretch;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.hdodenhof.circleimageview.CircleImageView;

public class Tpjzk extends AppCompatActivity {
    @BindView(R.id.bd)
    Button bd;
    @BindView(R.id.bu_http)
    Button buHttp;
    @BindView(R.id.bu_gif)
    Button buGif;
    private ImageView de_tp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tpjzk);
        initView();
        ButterKnife.bind(this);
    }
    private void onViewClicked(Tpjzk tpjzk, String s, ImageView de_tp) {
        RequestOptions options=new RequestOptions();
        options.centerCrop()
                .placeholder(R.mipmap.ye)//加载中显示的图片
                .error(R.mipmap.ye)//加载失败
                .circleCrop()//圆角图片
                .fallback(R.mipmap.ye);//加载回调过程中的图片
        //图片加载库要传入三个参数，上下文，图片地址，个图片控件id
        Glide.with(tpjzk).applyDefaultRequestOptions(options).load(s).into(de_tp);
    }
    @OnClick({R.id.bd, R.id.bu_http, R.id.bu_gif})
    public void onViewClicked1(View view) {
        switch (view.getId()) {
            case R.id.bd:
                //图片加载库要传入三个参数，上下文，图片地址，个图片控件id
                Glide.with(Tpjzk.this).load(R.mipmap.man).into(de_tp);
                break;
            case R.id.bu_http:
                onViewClicked(Tpjzk.this, "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574919734242&di=4282b0ecc0febcafcb8572d2fb727f38&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201701%2F13%2F20170113162528_jUuTF.png",de_tp);
                break;
                //这是一个动态的图片，值得一提的是gif图片的加载不能使用图片圆形控件de.hdodenhof:circleimageview否则加载不出来，要使用ImageView控件
            case R.id.bu_gif:
                onViewClicked(Tpjzk.this,"https://b-ssl.duitang.com/uploads/item/201610/24/20161024131608_mHF5x.gif",de_tp);
                break;
        }
    }
    private void initView() {
        de_tp = (ImageView) findViewById(R.id.de_tp);
    }
}
